package com.hong.concurrent.chapter14;

/**
 * @Author csh
 * @Description
 * @Date 2018/7/9 21:50
 */
public class CountDown
{
    /*总数*/
    private final int total;
    /*数器*/
    private int counter;

    public CountDown(int total) {
        this.total = total;
    }

    /*增加线程*/
    public void down(){
        synchronized (this){
            this.counter++;
            this.notifyAll();
        }
    }

    public  void await() throws InterruptedException {
        synchronized (this){
            while (counter!=total){
                this.wait();
            }
        }
    }
}
